package cn.calm.dialog.service.impl;

import org.apache.log4j.Logger;

import cn.calm.commons.exception.DeskException;
import cn.calm.commons.service.defaultimpl.DefaultServiceImpl;
import cn.calm.dialog.service.IButtonService;
import cn.calm.entity.Button;

public class ButtonServiceImpl<T extends Button> extends DefaultServiceImpl<T>
		implements IButtonService<T> {
	private static final Logger log = Logger
			.getLogger(ButtonServiceImpl.class);

	public void add(T t) throws DeskException {
		log.debug("add start");
//		DialogButton pk = new DialogButton();
//		pk.setDialog(t.getDialog().getId());
//		pk.setId(t.getId());
		T temp = baseDao.load(t.getClass(), t.getId());
		if (temp != null) {
			throw new DeskException("EM0001", t);
		}
		baseDao.insert(t);
		log.debug("add end");
	};

//	@SuppressWarnings("unchecked")
//	private String getMaxId(T t) {
//		log.debug("getMaxId start");
//		List<T> list = baseDao.listByProperty((Class<T>) Button.class,
//				"dialog", t.getDialog());
//		String id = "00";
//		if (list != null) {
//			String tempId;
//			for (Button b : list) {
//				tempId = b.getId();
//				id = tempId.compareTo(id) > 0 ? tempId : id;
//			}
//		}
//		log.debug("getMaxId start");
//		return String.format("%02d", Integer.parseInt(id) + 1);
//	}
}
